package com.accloud.utils;

public class Crc16Util {
    public static int GetCrc16(byte[] data, int length) {
        if (data == null) {
            return 0;
        }
        int crc = 0;
        int j = 0;
        while (true) {
            length--;
            if (length == 0) {
                return crc;
            }
            for (int i = 128; i != 0; i /= 2) {
                crc = (crc * 2) & -1;
                if ((65536 & crc) != 0) {
                    crc ^= 69665;
                }
                if ((data[j] & i) != 0) {
                    crc ^= 4129;
                }
            }
            j++;
        }
    }
}
